package com.qyhl.shop.shop;

import com.qyhl.shop.common.ShopUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.shop.ShopAdvSpaceBean;
import com.qyhl.webtv.commonlib.entity.shop.ShopMessageBean;
import com.qyhl.webtv.commonlib.entity.shop.ShopTypeBean;

import java.util.List;

public class ShopHomeModel implements ShopHomeContract.ShopHomeModel {
    private ShopHomePresenter mPresenter;

    public ShopHomeModel(ShopHomePresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getAdvList() {
        EasyHttp.post(ShopUrl.SHOP_HOME_ADV)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .execute(new SimpleCallBack<List<ShopAdvSpaceBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.setError("获取广告列表失败！");
                    }

                    @Override
                    public void onSuccess(List<ShopAdvSpaceBean> beanList) {
                        mPresenter.setAdvList(beanList);
                    }
                });
    }

    @Override
    public void getShopTypeList() {
        EasyHttp.post(ShopUrl.SHOP_HOME_TYPE)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .execute(new SimpleCallBack<List<ShopTypeBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.setError("获取类型列表失败！");
                    }

                    @Override
                    public void onSuccess(List<ShopTypeBean> beanList) {
                        mPresenter.setShopTypeList(beanList);
                    }
                });
    }

    @Override
    public void getMessage() {
        EasyHttp.post(ShopUrl.SHOP_HOME_MESSAGE)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .execute(new SimpleCallBack<List<ShopMessageBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.setMessage(null);
                    }

                    @Override
                    public void onSuccess(List<ShopMessageBean> beanList) {
                        mPresenter.setMessage(beanList);
                    }
                });
    }
}
